package com.ghsc.ghxc.jsb.ui.live.view

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cn.appcore.ext.getCompatColor
import com.cn.appcore.utils.GlideUtil
import com.cn.appcore.utils.GsonUtil
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ext.http.request
import com.ghsc.ghxc.jsb.ext.http.requestList
import com.ghsc.ghxc.jsb.ui.live.bean.GifListResultBean
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.BottomPopupView
import com.lxj.xpopup.enums.PopupAnimation

/**
 * 项目：JingShortVideo
 * 包名：com.bbl.jyShortVideo.ui.video.live.view
 * 类名：LiveAudienceListPopupView
 * 创建时间：2022/12/20 12:25
 * 创建人 @author： xiaolin
 * 描述 ：Todo... 排行榜
 */
class LiveTheChartsBangListPopupView  (context: AppCompatActivity,  vid:String, anchorId:String) : BottomPopupView(context) {
    private val mContext = context
    override fun getImplLayoutId() = R.layout.live_thecharts_list

    val vid=vid
    val anchorId=anchorId //主播id


    var mList = arrayListOf<GifListResultBean>()
    val mAdapter = ListAdapter()

    override fun onCreate() {
        super.onCreate()
        findViewById<TextView>(R.id.tvTitl).text="礼物榜"

        var  tvNodata= findViewById<TextView>(R.id.tvNodata)
        var  rvList= findViewById<RecyclerView>(R.id.rvList)
        rvList.layoutManager = LinearLayoutManager(mContext)
        rvList.adapter = mAdapter
        mAdapter.replaceData(mList)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            //todo 某个用户
//            XPopup.Builder(mContext)
//                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
//                .customHostLifecycle(lifecycle)
//                .dismissOnTouchOutside(true)
//                .navigationBarColor(mContext.getCompatColor(R.color.bg_dark_color))
//                .asCustom(
//                    LiveUserInfoPopupView(mContext,mAdapter.getItem(position).fuid,vid,anchorId)
//                )
//                .show()
        }

        val map: HashMap<String, Any> = HashMap()
        map["roomid"] = vid
        val json=  GsonUtil.mapToJsonStrObjEncryption(map)
        mContext.request({ ApiMarket.service.onLiveGiftTopData(json!!) }, {
            if (it.list.isNotEmpty()){
                tvNodata.visibility=View.GONE
                rvList.visibility=View.VISIBLE
                mAdapter.replaceData(it.list)
            }else{
                mAdapter.replaceData(it.list)
                tvNodata.visibility=View.VISIBLE
                rvList.visibility=View.GONE

            }
        })





    }
    override fun onDestroy() {
        super.onDestroy()
    }
    override fun getMaxWidth() = 0
    class ListAdapter  : BaseQuickAdapter<GifListResultBean, BaseViewHolder>(
        R.layout.live_thecharts_list_item) {
        override fun convert(helper: BaseViewHolder, item: GifListResultBean) {
            GlideUtil.ImageLoad(this.context, item.headimg, helper.getView(R.id.imgHead))
            helper.setText(R.id.tvName, item.nickname)
                .setText(R.id.tvPrice,item.totalprice)
            if (helper.layoutPosition==0){
                helper.setGone(R.id.tvId,true)
                    .setGone(R.id.imgId,false)
                    .setGone(R.id.tvBang,false)
                    .setImageResource(R.id.imgId,R.drawable.icon_item_1)
                    .setBackgroundResource(R.id.llItem,R.drawable.bang_item_bg)
            }else if (helper.layoutPosition==1){
                helper.setGone(R.id.tvId,true)
                    .setGone(R.id.imgId,false)
                    .setGone(R.id.tvBang,true)
                    .setImageResource(R.id.imgId,R.drawable.icon_item_2)
                    .setBackgroundResource(R.id.llItem,R.drawable.bang_item_bg)
            }else if (helper.layoutPosition==2){
                helper.setGone(R.id.tvId,true)
                    .setGone(R.id.imgId,false)
                    .setGone(R.id.tvBang,true)
                    .setImageResource(R.id.imgId,R.drawable.icon_item_3)
                    .setBackgroundResource(R.id.llItem,R.drawable.bang_item_bg)
            }else {
                helper.setGone(R.id.tvId,false)
                    .setGone(R.id.imgId,true)
                    .setGone(R.id.tvBang,true)
                    .setText(R.id.tvId,(helper.layoutPosition+1).toString())
                    .setBackgroundResource(R.id.llItem,0)
            }
        }

    }
}